<template>
	<view class="qxlj_back4 contain">
		<tabControl :current="userIndex" :values="menuBar" bgc="#fff" :fixed="true" :scrollFlag='true' :isEqually='true'
			@clickItem="onClickItem"></tabControl>
		<view class="list_box">
			<view class="item_box" v-for="(item,index) in glList" :key="index">
				<image @click="goDetail(item)" :src="item.Img" mode=""></image>
				<view class="bottom_box">
					<view class="text">
						<view class="title">{{item.Name}}</view>
						<view class="one">时间：<text>{{item.ProductSpecList[0].StartDate}}</text>-<text>{{item.ProductSpecList[0].EndDate}}</text> </view>
						<view class="tow">地点：西岭雪山</view>
					</view>
					<view class="btn" @click="goDetail(item)">
						<u-button text="查看详情" shape="circle"></u-button>
					</view>
				</view>
			</view>
			<empty v-if="glList.length === 0" :isfiexd="true" title="没有找到相关消息"></empty>
		</view>
	</view>
</template>

<script>
	import tabControl from '@/components/tabControl-tag/tabControl-tag.vue';
	import Config from '@/config/index.js';
	import empty from '@/components/empty.vue'
	import {
		getProductCategoryList,
		getGoodsList,
	} from '@/api/mall.js'
  import {useArticleApi} from "@/api/homePage";
	export default {
		components: {
			tabControl,
			empty
		},
		data() {
			return {
				userIndex: 0,
				menuBar: ["全部", ],
				glList: '',
				indexOf: 1,
				listID: 16, //活动类型ID
				allList: '', //分类源数据
			}
		},
		onLoad() {
			this.getShopType();
		},
		methods: {
			goDetail(item) {
				uni.navigateTo({
					url: `/mall_subpages/activitiesList/admissionTicketDetail?id=${item.Id}&type=${item.Type}`
				})
			},
			// 获取产品类型
			async getShopType() {
				try {
					const {
						Data
					} = await getProductCategoryList({
						ProductType: 16,
						Index: 1,
						Size: 15,
					});
					Data[0].ProductCategoryList.sort((a, b) => a.Sort - b.Sort);
					console.log(Data[0].ProductCategoryList)
					this.allList = Data[0].ProductCategoryList;
					Data[0].ProductCategoryList.forEach(con => {
						this.menuBar.push(con.Name)
					})
					this.getAllDate();

				} catch (e) {}
			},
			//日期转换
			timestampToTimeYMD(timestamp) {
				var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var Y = date.getFullYear() + '-';
				var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
				return Y + M + D;
			},
			//获取分类数据
			async getGLDate(e) {
				uni.showLoading({});
				try {
					const { Data } = await useArticleApi({
            ArticleCategoryId: 3396,
            Index: 1,
						Size: 10000,
					})
					uni.hideLoading();
					console.log(Data)
					Data.forEach(con => {
						if (con.ProductSpecList.length > 0) {
							con.ProductSpecList[0].StartDate = this.timestampToTimeYMD(con.ProductSpecList[0]
								.StartDate);
							con.ProductSpecList[0].EndDate = this.timestampToTimeYMD(con.ProductSpecList[0]
								.EndDate);
						}
					})
					this.glList = Data.Data;
				} catch (e) {

				}
			},
			//获取全部数据
			async getAllDate() {
				uni.showLoading({});
				try {
					const Data = await getGoodsList({
						TypeId: this.listID,
						Size: 10000,
					})
					uni.hideLoading();
					console.log(Data.Data)
					Data.Data.forEach(con => {
						if (con.ProductSpecList.length > 0) {
							con.ProductSpecList[0].StartDate = this.timestampToTimeYMD(con.ProductSpecList[0]
								.StartDate);
							con.ProductSpecList[0].EndDate = this.timestampToTimeYMD(con.ProductSpecList[0]
								.EndDate);

						}
					})

					console.log(Data.Data)
					this.glList = Data.Data;
				} catch (e) {

				}
			},
			onClickItem(val) {
				let _this = this;
				_this.userIndex = val.currentIndex;
				if (this.userIndex == 0) {
					_this.getAllDate()
				} else {
					_this.getGLDate(_this.userIndex - 1)
				}
			},
		},
		async onReachBottom() {
			this.indexOf += 1;
			if (this.userIndex == 0) {
				try {
					const Data = await getGoodsList({
						TypeId: this.listID,
						Size: 10000,
					})
					console.log(Data.Data)
					Data.Data.forEach(con => {
						con.AddTime = this.timestampToTimeYMD(con.AddTime);
					})
					let listArr = []
					this.glList = this.glList.concat(listArr);
				} catch (e) {

				}
			} else {
				try {
					const Data = await getGoodsList({
						ProductCategoryId: this.allList[this.userIndex - 1].Id,
						Size: 10000,
					})
					Data.Data.forEach(con => {
						con.AddTime = this.timestampToTimeYMD(con.AddTime);
					})
					let listArr = []
					this.glList = this.glList.concat(listArr);
				} catch (e) {

				}
			}
		},
	}
</script>

<style scoped lang="scss">
	.contain {
		width: 100%;
		min-height: 100vh;
	}

	.list_box {
		width: 100%;
		padding: 4%;
		padding-top: 98rpx;
		min-height: 100vh;

		.item_box {
			width: 100%;
			height: 480rpx;
			background-color: #fff;
			margin-top: 4%;
			border-radius: 5%;

			image {
				width: 100%;
				height: 291rpx;
			}

			.bottom_box {
				width: 100%;
				padding: 3%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.text {
					color: rgb(147, 154, 175);
					font-size: 28rpx;
					margin-bottom: 3%;

					.title {
						color: #333333;
						font-size: 32rpx;
						margin-bottom: 3%;
						white-space: nowrap;
						/* 不换行 */
						overflow: hidden;
						/* 超出部分隐藏 */
						text-overflow: ellipsis;
					}

				}

				.btn {
					display: flex;

					/deep/ .u-button--circle {
						background-color: #498FFF !important;
						color: #fff;
						border-color: transparent !important;
						width: 160rpx;
						margin: 0;
						height: 56rpx;
					}
				}
			}

		}
	}

	/deep/ .fixed {
		top: auto;
		bottom: auto;
	}
</style>